package com.example.tys.baseapplication.NetModel.okhttp.requset;

import android.support.annotation.NonNull;
import android.text.TextUtils;


import com.example.tys.baseapplication.NetModel.okhttp.OkHttpClientManger;

import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2016/10/27.
 */
public class PutRequestBuilder extends BaseRequest<PutRequestBuilder> {

    private String context;

    @Override
    public Call build() {
        Request req = new Request.Builder()
                .put(addStringBody(context))
                .url(url)
                .headers(addHead(heads))
                .tag(tag)
                .build();
        return OkHttpClientManger.getClient("").newCall(req);
    }

    private RequestBody addStringBody(@NonNull String context) {
        return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), TextUtils.isEmpty(context) ? "" : context);
    }

    public <T extends BaseRequest> T contextString(String context) {
        this.context = context;
        return (T) this;
    }

}
